package com.situ.blog.controller;

import com.situ.blog.pojo.Blog;
import com.situ.blog.service.IBlogService;
import com.situ.blog.service.impl.BlogServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/blog")
public class BlogServlet extends HttpServlet {
    private IBlogService blogService =new BlogServiceImpl();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String method = req.getParameter("method");
        switch (method){
            case "getBlogDetailPage":
                getBlogDetailPage(req, resp);
                break;
        }
    }

    private void getBlogDetailPage(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("BlogServlet.selectAll");
        //t_blog中的click_count+1
        String id = req.getParameter("id");
        Blog blog = blogService.selectById(Integer.parseInt(id));
        req.setAttribute("blog", blog);
        req.getRequestDispatcher("/WEB-INF/views/blog_detail.jsp").forward(req, resp);
    }
}
